package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemLaborServiceAndEmploymentBinding;
import com.sgb.kjwl.model.entity.packers.LabourServiceAndEmploymentEntity;
import com.sgb.kjwl.utils.PointUtils;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * @author younghow
 * @date 2021/7/6
 */
public class LaborServiceAndEmploymentAdapter  extends BaseRecycleAdapter<LabourServiceAndEmploymentEntity> {

    public LaborServiceAndEmploymentAdapter(Context context, List<LabourServiceAndEmploymentEntity> data) {
        super(context, R.layout.item_labor_service_and_employment, data);
    }

    @Override
    public void convert(ItemViewHolder holder, final LabourServiceAndEmploymentEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemLaborServiceAndEmploymentBinding binding = (ItemLaborServiceAndEmploymentBinding) holder.getmBinding();
        switch (entity.getSalaryType()) {
            case "1":
                String salary = PointUtils.originalPrice(entity.getSalary());
                binding.tvPrice.setText(String.format("%s元/%s",salary, (entity.getSalaryUnit() == 1 ? "月" : entity.getSalaryUnit() == 2 ? "季度" : "年")));
                break;
            case "2":
                binding.tvPrice.setText("电议");
                break;
            case "3":
                binding.tvPrice.setText("面议");
                break;
            default:
                break;
        }

        binding.tvTime.setText(String.format("%s%s%s",TextUtils.isEmpty(entity.getProvinceName()) ? "" : entity.getProvinceName() ,TextUtils.isEmpty(entity.getCityName()) ? "" : entity.getCityName(),TextUtils.isEmpty(entity.getAreaName()) ? "" : entity.getAreaName()));
        if (!TextUtils.isEmpty(entity.getProvinceName())) {
            if (!TextUtils.isEmpty(entity.getCityName())){
                if (!TextUtils.isEmpty(entity.getAreaName())){
                    binding.tvTime.setText(entity.getProvinceName() + entity.getCityName() + entity.getAreaName());
                    return;
                }
                binding.tvTime.setText(entity.getProvinceName() + entity.getCityName());
                return;
            }
            binding.tvTime.setText(entity.getProvinceName());
        }
    }
}
